// AccountManager.cpp: implementation of the CAccountManager class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "log4cplus_switch.h"
#include <string>
#include <list>
#include <map>
#include "SMSItem.h"
#include "SMSDispatch.h"
#include  "SMSQueue.h"
#include <common/Pool.h>
#include "NETLIB\TCPClient.h"
#include "Account.h"
#include "netlib/SocketEngine.h"
#include "AccountManager.h"
#include "IF.h"
#include "IFManager.h"
#include "SMSApp.h"

LOG4CPLUS_CLASS_IMPLEMENT( CAccountManager, _s_logger, "CAccountManager" );

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CAccountManager::CAccountManager()
{

}

CAccountManager::~CAccountManager()
{

}

void CAccountManager::SubmitSMS(CSMSItem* pSMS)
{
    if(m_Accounts.size() > 0)
	{
		CAccount* pAccount = m_Accounts[0];
		pAccount->SubmitSMS(pSMS);
	}
}

BOOL CAccountManager::AddInterface(int protocol, const char *destIP, unsigned short port)
{
    if(m_Accounts.size() > 0)
	{
		CAccount* pAccount = m_Accounts[0];
		return CSMSApp::GetInstance()->m_IFManager.AddInterface(pAccount, protocol, destIP, port);
	}
	return FALSE;
}

void CAccountManager::Test()
{
    CAccount* pAccount = new CAccount();
	m_Accounts.push_back(pAccount);
	AddInterface(0, "192.168.90.15", 7890);
}

void CAccountManager::PeriodDisptach()
{
	std::vector<CAccount*>::iterator it;
	for(it = m_Accounts.begin(); it!=m_Accounts.end();it++)
	{
		CAccount* p = *it;
		p->PeriodDispatch();
	}
}
